package net.zjitc.filter;

import net.zjitc.pojo.AdminUser;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created by rj1502 on 2017/11/14.
 */

public class AdminFileter implements Filter{
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpSession session = req.getSession();
        AdminUser admin = (AdminUser) session.getAttribute("admin");
        if (admin == null){
            req.getRequestDispatcher("/admin/index.jsp").forward(request,response);
        }else {
            chain.doFilter(request,response);
        }
    }

    public void destroy() {

    }
}
